package serverapp;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author paciks
 */
public class ServerConnection implements Runnable {

    public ArrayList<ConnectionHandler> connectionHandlerList = new ArrayList();
    private ConnectionHandler connectionHandler;    
    private ServerSocket serverSocket;
    
    public ServerConnection(ServerSocket aServerSocket){
        serverSocket = aServerSocket;
    }
    
    @Override
    public void run() {
        while(true){
                    try {             
                        System.out.println("WAITING FOR CONNECTION");
                        Socket socket = serverSocket.accept();
                        connectionHandler = new ConnectionHandler(socket);
                        connectionHandlerList.add(connectionHandler);
                        Thread t = new Thread(connectionHandler);
                        t.start();
                    } catch (IOException ex) {
                        Logger.getLogger(ServerView.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
    }

}
